<?php
FLEA::loadClass('Controller_Base');

class Controller_Client extends Controller_Base
{
	/**
	 * 用到的数据模块client
	 *
	 * @var object
	 */
	var	$_modelClient;
	/**
	 * client 模块
	 *
	 */
	function	Controller_Client()
	{
		$this->module	=	'Client';
		
		$this->_modelClient	=&	FLEA::getSingleton('Model_Client');
	}
	
	function actionClientsList()
	{
		$this->function	=	"ClientsList";
		$clients	=	$this->_modelClient->findAllClients();
		$this->viewdata['clients']	=	$clients;
		$this->show();
	}
	/**
	 * add inventor
	 *
	 */
	function	actionAddInventor()
	{
		$isLogin	=	$this->checkLogin();
		if($isLogin == 1)
		{
			$email	=	$_POST['Email'];
			$demo	=	$_POST['Message'];
			$firstName=	$_POST['FirstName'];
			$lastName=	$_POST['LastName'];
			$result	=	 $this->_modelClient->addInventor($firstName,$lastName,$email,$demo,$this->viewdata['user']['client']['ClientID']);
		}
		else
		{
			$result	=	-2;
		}
		
		if($isLogin == 1)
		{
			$inventors		=	$this->_modelClient->findAllInventors($this->viewdata['user']['client']['ClientID']);
		}
		
		$this->viewdata['result']	=	$result;
		$this->function				=	'InventorsList';
		$this->viewdata['inventors']=	$inventors;
		$this->show();
	}
	
	function	actionDeleteInventor()
	{
		$isLogin	=	$this->checkLogin();
		if($isLogin == 1)
		{
			$userID		=	$_POST['UserID'];
			$_modelUser	=&	FLEA::getSingleton('Model_User');
			$result		=	$_modelUser->removeByPkv($userID);
		}
		else
		{
			$result	=	-2;
		}
		
		if($isLogin == 1)
		{
			$inventors		=	$this->_modelClient->findAllInventors($this->viewdata['user']['client']['ClientID']);
		}
		
		$this->viewdata['result']	=	$result;
		$this->function				=	'InventorsList';
		$this->viewdata['inventors']=	$inventors;
		$this->show();
	}
	/**
	 * 显示clientslist 接口
	 *
	 */
	function	actionInventorsList()
	{
		
		$role	=	$this->checkLogin();
		if($role == 1)
		{
			$result	=	1;
			$inventors		=	$this->_modelClient->findAllInventors($this->viewdata['user']['client']['ClientID']);
		}
		else
		{
			$result	=	-2;
		}
		$this->viewdata['result']	=	$result;
		$this->function				=	'InventorsList';
		$this->viewdata['inventors']=	$inventors;
		$this->show();
	}
	/**
	 * 显示 viewInventor接口(显示所以inventor)
	 *
	 */
	function	actionViewInventor()
	{
		$this->viewdata['title']	=	'inventor information';
		$this->viewdata['h2']		=	'inventor information';
		
		$this->function				=	'ViewInventor';
		$inventorID		=	$_GET['InventorID'];
		$_modelInventor	=&	FLEA::getSingleton('Model_Inventor');
		$inventor		=	$_modelInventor->findInventor($inventorID);
		$this->viewdata['inventor']	=	$inventor;
		$this->show();
	}
	
	function actionGetClientInformation()
	{
		$isLogin	=	$this->checkLogin();
		if($isLogin == 1)
		{
			$this->function	=	"GetClientInformation";
			$this->show();
		}
		else
		{
			$this->showResult(-2);
		}
	}
	/**
	 * 修改 bill 信息
	 *
	 */
	function	actionEditBillingInformation()
	{
		$isLogin	=	$this->checkLogin();
		if($isLogin == 1)
		{
			$this->viewdata['user']['client']['Business']			=	$_POST['Business'];
			$this->viewdata['user']['client']['BillingAddress']		=	$_POST['BillingAddress'];
			$this->viewdata['user']['client']['BillingCity']		=	$_POST['BillingCity'];
			$this->viewdata['user']['client']['BillingState']		=	$_POST['BillingState'];
			$this->viewdata['user']['client']['BillingCountry']		=	$_POST['BillingCountry'];
			$this->viewdata['user']['client']['BillingPostalCode']	=	$_POST['BillingPostalCode'];
			$this->viewdata['user']['client']['TaxID']				=	$_POST['TaxID'];
			$this->viewdata['user']['client']['Description']		=	$_POST['Description'];
			$result	=	$this->_modelClient->saveClient($this->viewdata['user']['client']);
			
		}
		else
		{
			$result	=	-2;
		}
		
		$this->viewdata['result']	=	$result;
		$this->viewdata['client']	=	$this->_modelClient->findClient($this->viewdata['user']['client']['ClientID']);
		$this->function				=	"ShowClient";
		$this->show();
	}
	
	function	actionUpdateClient()
	{
		$isLogin	=	$this->checkLogin();
		if($isLogin == 5)
		{
			$client['ClientID']	=	$_POST['ClientID'];
			$client['BAuction']	=	$_POST['BAuction'];
			
			$clientTem	=	$this->_modelClient->findClient($client['ClientID']);
			$client['BAuction']	=	$clientTem['BAuction']==1?0:1;
			$result	=	$this->_modelClient->save($client);
			
		}
		else
		{
			$result	=	-2;
		}
		
		$this->showResult($result);
	}
}
?>